package com.weihuachao.repair;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.lidroid.xutils.http.RequestParams;
import com.weihuachao.entity.Result;
import com.weihuachao.https.BasicRequestCallBck;
import com.weihuachao.https.XUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Virgo on 2016/8/4.
 */
public class FeedbackActivity extends Activity {
    @BindView(R.id.content_feedback)
    EditText contentFeedback;
    @BindView(R.id.back_feedback)
    Button backFeedback;
    @BindView(R.id.submit_feedback)
    Button submitFeedback;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        XUtils.init(this);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.content_feedback, R.id.back_feedback, R.id.submit_feedback})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back_feedback:
                finish();
                break;
            case R.id.submit_feedback:
                if (contentFeedback.getText().toString().length()>12) {
                    RequestParams params = new RequestParams();
                    params.addBodyParameter("feedback.content", contentFeedback.getText().toString());
                    XUtils.send(XUtils.ADDFEEDBAK, params, new BasicRequestCallBck<Result<Boolean>>() {
                        @Override
                        public void success(Result<Boolean> data) {
                            if (data.state == 1) {
                                XUtils.show("提交意见成功");
                                startActivity(new Intent(FeedbackActivity.this, MainActivity.class));
                            } else {
                                XUtils.show("提交意见失败");
                            }
                        }
                    });
                } else {
                    Toast.makeText(FeedbackActivity.this, "抱歉，意见内容过短！",Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}
